﻿/*
 * Erstellt mit SharpDevelop.
 * Benutzer: Kai Patrick
 * Datum: 19.03.2008
 * Zeit: 10:13
 * 
 * Sie können diese Vorlage unter Extras > Optionen > Codeerstellung > Standardheader ändern.
 */

using System;
using System.Windows.Forms;
using System.Collections;
using System.Collections.Generic;

namespace Gamadus.Designer
{
	/// <summary>
	/// Description of ListViewEventSorter.
	/// </summary>
	public class ListViewEventSorter : IComparer
	{
		List<EventType> sortOrder = new List<EventType>();
		EditObjectForm form;
		public ListViewEventSorter(EditObjectForm form)
		{
			this.form = form;
			
			sortOrder.Add(EventType.Create);
			sortOrder.Add(EventType.Step);
			sortOrder.Add(EventType.Draw);
		}
		
		public int Compare(object x, object y)
		{
			Event eventX,eventY;

			try
			{
				eventX = form.EventList[(ListViewItem)x];
				eventY = form.EventList[(ListViewItem)y];
			} catch (KeyNotFoundException) {
				return 0;
			}
			
			
			int indexX = sortOrder.IndexOf(eventX.Type);
			int indexY = sortOrder.IndexOf(eventY.Type);
	
			// Compare the two items
			if(indexX > indexY)
				return 1;
			else if(indexX < indexY)
				return -1;
			else
				return 0;
		}
	}
}
